<template>
	<view class="">
		<!-- <u-button @click="clear">清空列表</u-button> -->
		<u-waterfall v-model="flowList" ref="uWaterfall">
			<template v-slot:left="{leftList}">
				<view @tap="GoGoods(item)" class="demo-warter" v-for="(item, index) in leftList" :key="index">
					<view class="imagess">
						<u-lazy-load threshold="-450" border-radius="10" :image="item.thumbnail" :index="index"></u-lazy-load>
						<view v-if="item.distance != undefined" class="addresLabel">
							<image src="../../static/image/location@2x.png" mode=""></image>
							{{item.distance}}
						</view>
					</view>
					<view class="demo-title  p16">
						{{item.name}}

					</view>
					<view class="demo-price p16">
						<span>￥</span> {{item.price}}
					</view>
					<view class="demo-shop p16">
						<view class="fl one">
							<image class="vm" :src="item.avatarImg" mode=""></image>
							{{item.username}}
						</view>
						<view class="fr">
							销量 {{item.sales}}
						</view>
					</view>
				</view>
			</template>
			<template v-slot:right="{rightList}">
				<view @tap="GoGoods(item)" class="demo-warter" v-for="(item, index) in rightList" :key="index">
					<view class="imagess">
						<u-lazy-load threshold="-450" border-radius="10" :image="item.thumbnail" :index="index"></u-lazy-load>
						<view v-if="item.distance != undefined" class="addresLabel">
							<image src="../../static/image/location@2x.png" mode=""></image>
							{{item.distance}}
						</view>
					</view>
					<view class="demo-title  p16">
						{{item.name}}

					</view>
					<view class="demo-price p16">
						<span>￥</span> {{item.price}}
					</view>
					<view class="demo-shop p16">
						<view class="fl one">
							<image class="vm" :src="item.avatarImg" mode=""></image>
							{{item.username}}
						</view>
						<view class="fr">
							销量 {{item.sales}}
						</view>
					</view>
				</view>
			</template>
		</u-waterfall>
		<!-- <u-loadmore bg-color="rgb(240, 240, 240)" <:statu></:statu>s="loadStatus" ></u-loadmore> -->
	</view>
</template>

<script>
	export default {
		data() {
			return {
				loadStatus: 'loadmore',
				flowList: [],
				list: []
			}
		},
		created() {
			this.addRandomData();
		},
		onReachBottom() {
			this.loadStatus = 'loading';
			// 模拟数据加载
			setTimeout(() => {
				// this.addRandomData();
				this.loadStatus = 'loadmore';
			}, 1000)
		},
		methods: {
			GoGoods(item) {
				this.$navigateTo('../GoodsDetails/GoodsDetails?id=' + item.id)
			},
			addRandomData() {
				for (let i = 0; i < this.list.length; i++) {
					// let index = this.$u.random(0, this.list.length - 1);
					// 先转成字符串再转成对象，避免数组对象引用导致数据混乱
					let item = JSON.parse(JSON.stringify(this.list[i]))
					// item.id = this.$u.guid();
					this.flowList.push(item);
				}
				uni.removeStorageSync('dynamicSet')
			},
			UpData() {
				this.list = uni.getStorageSync('productSet')
				this.addRandomData()
			},
			hello() {
				console.log('hello');
			},
			remove(id) {
				this.$refs.uWaterfall.remove(id);
			},
			clear() {
				this.$refs.uWaterfall.clear();
			}
		}
	}
</script>

<style>
	/* page不能写带scope的style标签中，否则无效 */
	page {
		background-color: rgb(240, 240, 240);
	}
</style>

<style lang="scss" scoped>
	.demo-warter {
		border-radius: 8px;
		margin: 5px;
		background-color: #ffffff;
		position: relative;
		padding-bottom: 22rpx;
	}

	.imagess {
		position: relative;
	}

	.addresLabel {
		position: absolute;
		bottom: 10rpx;
		left: 10rpx;
		height: 40rpx;
		line-height: 40rpx;
		background: rgba(0, 0, 0, 1);
		opacity: 0.5;
		border-radius: 20rpx;
		font-size: 20rpx;
		font-family: PingFang SC;
		font-weight: 400;
		// color:rgba(255,255,255,1);
		color: white;
		padding: 0 20rpx;

		image {
			width: 16rpx;
			height: 20rpx;
			margin-right: 8rpx;
		}
	}

	.u-close {
		position: absolute;
		top: 32rpx;
		right: 32rpx;
	}

	.demo-image {
		width: 100%;
		border-radius: 4px;
	}

	.demo-title {
		font-size: 28rpx;
		font-family: PingFang SC;
		font-weight: bold;
		color: rgba(26, 26, 26, 1);
		margin-top: 5px;
		color: $u-main-color;
	}

	.demo-tag {
		display: flex;
		margin-top: 5px;
	}

	.demo-tag-owner {
		background-color: $u-type-error;
		color: #FFFFFF;
		display: flex;
		align-items: center;
		padding: 4rpx 14rpx;
		border-radius: 50rpx;
		font-size: 20rpx;
		line-height: 1;
	}

	.demo-tag-text {
		border: 1px solid $u-type-primary;
		color: $u-type-primary;
		margin-left: 10px;
		border-radius: 50rpx;
		line-height: 1;
		padding: 4rpx 14rpx;
		display: flex;
		align-items: center;
		border-radius: 50rpx;
		font-size: 20rpx;
	}

	.demo-price {
		font-size: 30rpx;
		font-family: PingFang SC;
		font-weight: bold;
		color: rgba(246, 82, 16, 1);
		margin-top: 5px;

		span {
			font-size: 24rpx;
		}
	}

	.demo-shop {
		overflow: hidden;
		font-size: 20rpx;
		font-family: PingFang SC;
		font-weight: 400;
		color: rgba(102, 102, 102, 1);

		.fl {
			width: 180rpx;
		}

		image {
			width: 36rpx;
			height: 36rpx;
			border-radius: 50%;
			margin-right: 6rpx;
		}

		margin-top: 5px;
	}
</style>
